package com.hngates.architecture.controller;

import com.hngates.architecture.domain.ArcLabourSubCompany;
import com.hngates.architecture.domain.ArcLabourSubCompanyDetails;
import com.hngates.architecture.service.IArcLabourSubCompanyDetailsService;
import com.hngates.architecture.service.IArcLabourSubCompanyService;
import com.hngates.common.annotation.Log;
import com.hngates.common.constant.Constants;
import com.hngates.common.core.controller.BaseController;
import com.hngates.common.core.domain.AjaxResult;
import com.hngates.common.core.page.TableDataInfo;
import com.hngates.common.enums.BusinessType;
import com.hngates.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 劳务分包单位具体情况Controller
 *
 * @author jwhe
 * @date 2022-07-04
 */
@Controller
@RequestMapping("/architecture/labourSubCompanyDetails")
public class ArcLabourSubCompanyDetailsController extends BaseController {
    private String prefix = "architecture/labourSubCompanyDetails";

    @Autowired
    private IArcLabourSubCompanyService arcLabourSubCompanyService;
    @Autowired
    private IArcLabourSubCompanyDetailsService arcLabourSubCompanyDetailsService;

    @RequiresPermissions("architecture:labourSubCompanyDetails:view")
    @GetMapping()
    public String labourSubCompanyDetails(ModelMap modelMap) {
        //return prefix + "/labourSubCompanyDetails";
        ArcLabourSubCompany arcLabourSubCompany = new ArcLabourSubCompany();
        arcLabourSubCompany.setDelFlag(Constants.DEl_FLAG_0);
        List<ArcLabourSubCompany> arcLabourSubCompanies = arcLabourSubCompanyService.selectArcLabourSubCompanyList(arcLabourSubCompany);
        modelMap.put("labourSubs", arcLabourSubCompanies);
        return "architecture/labourSubCompanyDetails/labourSubCompanyDetails";
    }

    /**
     * 查询劳务分包单位具体情况列表
     */
    @RequiresPermissions("architecture:labourSubCompanyDetails:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ArcLabourSubCompanyDetails arcLabourSubCompanyDetails) {
        startPage();
        List<ArcLabourSubCompanyDetails> list = arcLabourSubCompanyDetailsService.selectArcLabourSubCompanyDetailsList(arcLabourSubCompanyDetails);
        return getDataTable(list);
    }

    /**
     * 导出劳务分包单位具体情况列表
     */
    @RequiresPermissions("architecture:labourSubCompanyDetails:export")
    @Log(title = "劳务分包单位具体情况", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ArcLabourSubCompanyDetails arcLabourSubCompanyDetails) {
        List<ArcLabourSubCompanyDetails> list = arcLabourSubCompanyDetailsService.selectArcLabourSubCompanyDetailsList(arcLabourSubCompanyDetails);
        ExcelUtil<ArcLabourSubCompanyDetails> util = new ExcelUtil<ArcLabourSubCompanyDetails>(ArcLabourSubCompanyDetails.class);
        return util.exportExcel(list, "劳务分包单位具体情况数据");
    }

    /**
     * 新增劳务分包单位具体情况
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存劳务分包单位具体情况
     */
    @RequiresPermissions("architecture:labourSubCompanyDetails:add")
    @Log(title = "劳务分包单位具体情况", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ArcLabourSubCompanyDetails arcLabourSubCompanyDetails) {
        return toAjax(arcLabourSubCompanyDetailsService.insertArcLabourSubCompanyDetails(arcLabourSubCompanyDetails));
    }

    /**
     * 修改劳务分包单位具体情况
     */
    @RequiresPermissions("architecture:labourSubCompanyDetails:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        ArcLabourSubCompanyDetails arcLabourSubCompanyDetails = arcLabourSubCompanyDetailsService.selectArcLabourSubCompanyDetailsById(id);
        mmap.put("arcLabourSubCompanyDetails", arcLabourSubCompanyDetails);
        return prefix + "/edit";
    }

    /**
     * 修改保存劳务分包单位具体情况
     */
    @RequiresPermissions("architecture:labourSubCompanyDetails:edit")
    @Log(title = "劳务分包单位具体情况", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ArcLabourSubCompanyDetails arcLabourSubCompanyDetails) {
        return toAjax(arcLabourSubCompanyDetailsService.updateArcLabourSubCompanyDetails(arcLabourSubCompanyDetails));
    }

    /**
     * 删除劳务分包单位具体情况
     */
    @RequiresPermissions("architecture:labourSubCompanyDetails:remove")
    @Log(title = "劳务分包单位具体情况", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(arcLabourSubCompanyDetailsService.deleteArcLabourSubCompanyDetailsByIds(ids));
    }
}
